package cn.walls1717.wallsmall.order.web;

import cn.walls1717.wallsmall.order.entity.OrderEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.Date;
import java.util.UUID;

/**
 * @author walls1717
 * @since 2022/11/17 21:42
 **/
@Controller
@Slf4j
public class TestController {
    @Resource
    private RabbitTemplate rabbitTemplate;

    @GetMapping("/{page}.html")
    public String listPage(@PathVariable("page") String page) {
        return page;
    }

    @GetMapping("/order/test")
    @ResponseBody
    public String createOrderTest() {
        OrderEntity orderEntity = new OrderEntity();
        orderEntity.setOrderSn(UUID.randomUUID().toString());
        orderEntity.setModifyTime(new Date());
        rabbitTemplate.convertAndSend("order-event-exchange", "order.create.order", orderEntity);
        return "ok";
    }

    /*@RabbitListener(queues = "order.release.order.queue")
    public void listener(OrderEntity order, Channel channel, Message message) throws IOException {
        log.info("order -> {}", order.getOrderSn());
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
    }*/
}
